﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;

namespace Tetris
{
    static class CheckList
    {
        public static bool IsOnFloor(Figure figure, GameField gamefield)
        {
            if ((figure.Node1.Y + 1 == gamefield.StartY + gamefield.height - 1) || (figure.Node2.Y + 1 == gamefield.StartY + gamefield.height - 1)
                || (figure.Node3.Y + 1 == gamefield.StartY + gamefield.height - 1) || (figure.Node4.Y + 1 == gamefield.StartY + gamefield.height - 1))
                return true;
            else return false;
        }

        public static bool IsFigureOnField(Figure figure, GameField field)
        {
            if ((field.IsOnField(figure.Node1.X, figure.Node1.Y)) && (field.IsOnField(figure.Node2.X, figure.Node2.Y))
                && (field.IsOnField(figure.Node3.X, figure.Node3.Y)) && (field.IsOnField(figure.Node4.X, figure.Node4.Y)))
                return true;
            else return false;
        }

        public static bool IsReadyToDraw(Node node, GameField field)
        {
            if (field.IsOnField(node.X, node.Y))
            {
                Console.SetCursorPosition(node.X, node.Y);
                return true;
            }
            return false;
        }

        public static bool IsOnOtherFigures(Figure figure, List<Node> nodesList)
        {
            foreach (var node in nodesList)
            {
                if (figure.Node1.Y + 1 == node.Y && figure.Node1.X == node.X)
                    return true;
            }
            foreach (var node in nodesList)
            {
                if (figure.Node2.Y + 1 == node.Y && figure.Node2.X == node.X)
                    return true;
            }
            foreach (var node in nodesList)
            {
                if (figure.Node3.Y + 1 == node.Y && figure.Node3.X == node.X)
                    return true;
            }
            foreach (var node in nodesList)
            {
                if (figure.Node4.Y + 1 == node.Y && figure.Node4.X == node.X)
                    return true;
            }
            return false;
        }

        public static bool IsGameOver(List<Node> nodesList)
        {
            foreach (var node in nodesList)
            {
                if (node.Y == 5)// проверка достижения "потолка" поля, сейчас это 5
                    return true;
            }
            return false;
        }
        

        public static bool IsRowFull(List<Node> nodesList, int y)
        {
            int count = 0;
            foreach (var node in nodesList)
            {
                if (y == node.Y)
                    count++;
            }
            if (count == 10)
                return true;
            return false;
        }
    }
}
